Go Down

Topic: Help with Loops and IFs?? (Read 1 time) previous topic - next topic

dhenry

Code: [Select]
If StarterIn = HIGH THEN StarterCheck


The C equivalent would be

Code: [Select]
If (StarterIn == HIGH) {StarterCheck;}

dhenry

A loop version of it would be

Code: [Select]
while(StarterIn == HIGH) continue;

LockDots


Quote
I meant to write just the name of the tag (StarterCheck) without GoSub before it.


A label is _not_ a sub(routine). GoSub is basic dialect for "call a subroutine". Goto is _not_ the same as gosub.

Did you read http://arduino.cc/en/Tutorial/HomePage Section 1. Basics ? You seem to miss some fundamental bits.


I understand the difference between a GoSub and a Goto. A Goto does just what it implies, it goes to a certain part of the program and continues on to the rest of the code from there whereas a GoSub goes to a subroutine and returns to the following line from where it was called.

In pBasic to accomplish what I have in my flowchart I would write the following:

Code: [Select]

StarterCheck:
If StarterIn = LOW THEN StarterCheck


StarterCheck: is a placemarker, tag, or label (whatever you want to call it).
The "IF" statement would check to see if variable StarterIn is LOW then it will force the program to return to the tag/label "StarterCheck:". This keeps the program looping from "StarterCheck:" to the IF statement as long as variable StarterIn is LOW. Once it goes HIGH, the IF statement is no longer true and so the program falls through to whatever line of code is after the IF statement.

note: In my original post my IF statement was written incorrectly (used HIGH, instead of LOW), the correction has been made above.

So I guess my real question is, how do I create a tag, label, or placemarker in C for the program to go to when an IF condition has been met?

PaulS

Quote
So I guess my real question is, how do I create a tag, label, or placemarker in C for the program to go to when an IF condition has been met?   

You don't. It executes the next instruction (or block of instructions.
Code: [Select]
if(this == that)
   doThis();

or
Code: [Select]
if(them == those)
{
   doThis();
   andThis();
   andDontForgetThis();
   meToo();
}

LockDots

Haha. Well that kind of stinks.... There's got to be a way to do it, no? :(

I need the program to get to a certain point where it gets stuck in a loop waiting for an input to go HIGH. Once it goes HIGH I would like it to fall through to the rest of the code.

Go Up