Shop OBEX P1 Docs P2 Docs Learn Events
While with a variable for C — Parallax Forums

While with a variable for C

Hi all.
I would like to ask if I can use the while function in the while(1) with a variable a push button.
For example
while(1)
{
op = input(16);
while( op == 1)
{
calculations
op = input(16);
}
}

something like the DO UNTIL... LOOP for the BS2.
Thank you

Comments

  • DavidZemonDavidZemon Posts: 2,973
    edited 2016-02-09 15:21
    johnproko wrote: »
    Hi all.
    I would like to ask if I can use the while function in the while(1) with a variable a push button.
    For example
    while(1)
    {
    op = input(16);
    while( op == 1)
    {
    calculations
    op = input(16);
    }
    }

    something like the DO UNTIL... LOOP for the BS2.
    Thank you

    yes :) that would be perfect. There's also the lesser known "do-while".
    while(1)
    {
      do
      {
        // calculations
      } while( 1 == input(16) );
    
      // do other stuff
    }
    

    --Edit--
    Fixed my bad code :)
  • Sure, the 2nd step is not even needed

    while(input(16)) { ... }

    And then there is the do, while
    incase you want it done at least one time.

    Disassembly is great to use to see if the compilers assembler is doing what you want.

Sign In or Register to comment.