Not Yet Answered # For loop test condition

William Hemsworth 1,339 snehil_khanor 1 Discussion Starter bigsurya Need some help with this Array. I am trying to get the sum of the even numbers and the sum of the odd numbers using a for each loop. I know the answers to what I am trying to achive are sum of even = 84 and the sum of ...

0

Your condition for that loop is:

`(s[i] != '\0') || (s[i] != ' ')`

Now think, is there **any** way that expression will ever be false in order to break out the loop? If **s** is a null-terminator, the loop wont break as **s** isn't a space, and the same the other way round.

The condition would make sense if instead of having **||**, you used **&&**, but I don't know your intentions.

2

yes u can .. but m afraid it would be an infinite loop...

your test condition is: s*!='\0')|| s !=' '*

which means if any of these two conditions is true then overall condition will be true which means loop will be incremented...

Here is the Truth table for OR:

False||False=False

False||True=True

True||False=True

True||True=True

which means condition will only be false when both conditions are false.. i.e loop will break only when s*='\0' as well as =' ' at the same time .. which is not actually possible...*

but if u want loop to be terminated.. then.. use AND

truth table for AND is:

False&&False=False

False&&True=False

True&&Fasle=False

True&&True=True

which implies condition will fail if any 1 of the condition is false.. i.e if s*='/0' or ' ' any of these..
hope u get it..
njjoy!!
- Snehil :)*

0

hey guys...thanks for the replies...I'm sorry to have put tht kinda inexplicable code...actually tht loop is gonna traverse down the array n not up/// anyway i jst wanted to knw whether i can hv a test condition with a '||'...thanks a lot

This article has been dead for over six months. Start a new discussion instead.

Recommended Articles

When I execute this progammatically, I get a table with row heights much larger than when I do this manually.

Note : Sel is the Word.Selection object and the Clipboard contains an Excel Table.

```
public void AddClipboard()
{
Sel.PasteExcelTable(false,false, false);
var t = Sel.Tables[Sel.Tables.Count];
t.AutoFitBehavior(Word.WdAutoFitBehavior.wdAutoFitContent);
}
```

the function that I created to find the ...