#1
  1. No Profile Picture
    Permanently Banned
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2012
    Posts
    3
    Rep Power
    0
    Ok so I need help in understanding 'while' loops and using them.
    If someone clicks no in a dialogue box, how can I get it to loop back to the original question? And how can I keep it looping until the value is true?
    with the javascipt im using we have the following dialogue boxes:
    alert (simple press ok to carry on)
    confirm (a yes or no box)
    request (the user has to type something ot carry on)
    So for example:

    String newNum = request("Please enter a new number you would like");
    String confirmNew = request("Please confirm the new number");
    if (newNum.equals(""+confirmNew))
    {
    alert("The new number has been processed");
    }
    else
    {
    confirm("The two numbers entered did not match. Try again?");
    }

    So if the user clicks yes to trying again how can I loop back to the start? And if the user clicked no how can I put an alert dialogue box to say "Cancelled" ?

    Thank you for any help given! I got the basics but I cant work out looping!!

    Comments on this post

    • ptr2void disagrees : Go away, useless SEO spammer
    Last edited by ManiacDan; September 18th, 2012 at 07:06 AM.
  2. #2
  3. Confused badger
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Mar 2009
    Location
    West Yorkshire
    Posts
    1,047
    Rep Power
    487
    Originally Posted by djdigitalgirl99
    Ok so I need help in understanding 'while' loops and using them.
    If someone clicks no in a dialogue box, how can I get it to loop back to the original question? And how can I keep it looping until the value is true?
    with the javascipt im using we have the following dialogue boxes:
    alert (simple press ok to carry on)
    confirm (a yes or no box)
    request (the user has to type something ot carry on)
    So for example:

    String newNum = request("Please enter a new number you would like");
    String confirmNew = request("Please confirm the new number");
    if (newNum.equals(""+confirmNew))
    {
    alert("The new number has been processed");
    }
    else
    {
    confirm("The two numbers entered did not match. Try again?");
    }

    So if the user clicks yes to trying again how can I loop back to the start? And if the user clicked no how can I put an alert dialogue box to say "Cancelled" ?

    Thank you for any help given! I got the basics but I cant work out looping!!


    djdigitalgirl[dot]com
    Hi there

    Couple of quick things:-
    1. You've posted a Javascript question in a PHP forum, a mod should move this if you're wanting help with Javascript.
    2. You should post code in appropriate tags.

    Ok, now they're out of the way ...
    The code you posted is an IF / ELSE so will only execute ONCE. A "While" loop will loop until a certain condition is met (which you define at the start of the loop).

    For example, in PHP you would write:

    PHP Code:
    <?php
    // Give $x an initial value, 4 in this case
    $x 4;

    // Configure the while loop, in this case, WHILE X is not 0, perform the loop
    while ($x != 0) {
      
    // Display the current value of $x
      
    echo $x "<br />";

      
    // Take 1 away from $x
      
    $x--;
    }

    // When $x reaches 0, this bit of code is then executed
    echo "Done!";

    ?>
    With regards to your Javascript question, this link should answer all your questions.
    "For if leisure and security were enjoyed by all alike, the great mass of human beings who are normally stupefied by poverty would become literate and would learn to think for themselves; and when once they had done this, they would sooner or later realise that the privileged minority had no function and they would sweep it away"
    - George Orwell, 1984

IMN logo majestic logo threadwatch logo seochat tools logo