Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

C programming question

Status
Not open for further replies.
J

jjimenez101

Guest
hello,

I have a programming question, say I have the following C program:

main()

{

While (1)

{

if ( condition2)

{
Perform A
}

else
{
Perform B
}

Statement D

} //end while loop

} // end main loop

My question here is: will the program ever reach statementD? What I am thinking is that if condition 2 is met, it will perform A, and if not, then it will perfrom B. Then it will never get to the statement D because Im thinking that once the statement in the If section or the else section is performed, the program will go back to the begining and this process will continure for ever and not reach statment D ever.
 
Ignoring the fact that there isn't a single ; in your code.....
It will always reach Statement D because once it is done with the If/Then/Else statement, execution continues at the next statement which is D
 
Thats why indentation is recommended.

It makes it so much easier to read.
Code:
main()
{
	While (1)
	{
		if ( condition2)
		{ 
			Perform A
		}
		else
		{
			Perform B
		}
		Statement D
	} //end while loop
} // end main loop
 
sure it will reach statement D after fineshing B or finishing A programs is executed line by line and there is nothing informs that the execution should go to the beginning of the prog. without executing statement D :)
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top