Results 1 to 4 of 4

Math Help - While Loops! Help me please!!!!

  1. #1
    Newbie
    Joined
    Oct 2007
    Posts
    3

    While Loops! Help me please!!!!

    I am having issues with while loops ( or do while loops I think is another name for them). While loops seem so easy and I feel like I get them until I have to do problems on my own.

    Can anyone explain them to me?

    here is a problem from my homework:
    which values of b do the following algorithm terminate?

    begin
    k:=b
    while k<5 do
    k:=2k-1

    Now the answer I get is that it terminates at 3

    b k k<5
    3 5 False (cause k cannot = 5 right?)

    but the answer in the back of the book is b>(or equal to)=2.

    What am I doing wrong?!?


    Also I get confused when another step is added in the while loop, such as:

    begin
    k:=1
    while k<(or equal to) 4 do
    k:=k^2
    print k
    k:=k+1
    end




    I am just not getting these. I think I may be over complicating them.

    Help me uncomplicate the whole thing. Please!!!!
    Follow Math Help Forum on Facebook and Google+

  2. #2
    Grand Panjandrum
    Joined
    Nov 2005
    From
    someplace
    Posts
    14,972
    Thanks
    4
    Quote Originally Posted by speakeasy View Post
    I am having issues with while loops ( or do while loops I think is another name for them). While loops seem so easy and I feel like I get them until I have to do problems on my own.

    Can anyone explain them to me?

    here is a problem from my homework:
    which values of b do the following algorithm terminate?

    begin
    k:=b
    while k<5 do
    k:=2k-1
    On entry to the look k=3, so the code is executed and k becomes 5.
    We return to the top of the loop and perform the test k<5?, which fails
    so we exit the loop with k=5.

    RonL
    Follow Math Help Forum on Facebook and Google+

  3. #3
    Grand Panjandrum
    Joined
    Nov 2005
    From
    someplace
    Posts
    14,972
    Thanks
    4
    Quote Originally Posted by speakeasy View Post
    Also I get confused when another step is added in the while loop, such as:

    begin
    k:=1
    while k<(or equal to) 4 do
    k:=k^2
    print k
    k:=k+1
    end
    On entry to the loop k=1, so the code between the do and end is executed;
    k becomes 1, which is printed, then k becomes 2.

    We now return to the top of the loop with k=2, which is <=4 so the code
    inside the loop is again executed. k becomes k^2 or 4, which is printed,
    then k becomes 5.

    We now return to the top of the loop with k=5, which fails the test so
    we exit the loop with k=5.

    RonL
    Follow Math Help Forum on Facebook and Google+

  4. #4
    Newbie
    Joined
    Oct 2007
    Posts
    3

    Thanks

    Thank you so much Captain Black. I think I got it.
    Follow Math Help Forum on Facebook and Google+

Similar Math Help Forum Discussions

  1. Need help with Matlab (Loops)
    Posted in the Math Software Forum
    Replies: 1
    Last Post: February 8th 2011, 12:50 AM
  2. matlab for loops?
    Posted in the Math Software Forum
    Replies: 5
    Last Post: February 28th 2010, 09:49 PM
  3. Multiplication loops?
    Posted in the Math Software Forum
    Replies: 2
    Last Post: July 13th 2009, 07:24 AM
  4. While loops
    Posted in the Math Software Forum
    Replies: 3
    Last Post: May 11th 2009, 06:54 PM
  5. how many loops in a coil
    Posted in the Math Topics Forum
    Replies: 2
    Last Post: February 20th 2008, 10:09 AM

Search Tags


/mathhelpforum @mathhelpforum