This is just for my information and I don't really have much need for it... But, I would like to know anyway :D.

#1. Is a for or while statement faster than one another? As in, if someone put a for would it be faster (application-wise, not when their typing it) than a while statement?

Example:

for(i=0;i<string.length;i++);

 OR

 i=0;
 while(i<string.length){
    i++;
 }

#2. Is it faster (application-wise, not typing) to use no { and just the ; or not? As in...

while(i<string.length){
i++;
}

OR

while(i<string.length)
i++;

#3. What is more efficient, if different, using a boolean for true/false or an int for 1/0?

Recommended Answers

All 2 Replies

1) Depends on the compiler and whether you compile the program for debug or release. Most modern compiler will make them the same code, despite the errors in the code snippets you posted.

2) Speed has nothing to do with it -- the { and } are there to block lines of code. I like to use { and } even with one liners for readability and ease of future enhancements.

3) One is not more efficient than the other -- is readability and maintainability that counts. Use boolean true/false whereever it makes sense to do that.

Awesome, glad to know thanks ^_^.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.