W10-Control1

W10-Control1 - Flow of Control 1 10/10/05 1 Relational...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
10/10/05 1 Flow of Control 1 10/10/05 2 Relational Operators (Tests) • < > <= >= == and != • Binary operators with integer values. • In C, zero means false and one means true. • But also anything non-zero is true . 10/10/05 3 Some Examples • Given a = 2, b = 3, c = 'a', d = 'A' • a == b has value 0 (false) • a != b has value 1 (true) • a = b has value 3 (true, assignment! -- not a test) • c == d has value 0 (false) • c == 'a' has value 1 (true)
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
4 if/else Statement • The 'else' is optional. • If more than one statement, then enclose in { }. • Often nested to express complicated conditions. if (test_expression) /*code to execute if test_expression true*/ ; else /*code to execute if test_expression false */ ; 10/10/05 5 Simple if/else int value = -1; if (value >= 0) printf("positive or zero"); else printf("negative"); 10/10/05 6 Extended Example - Leap Years • The rule: Every year divisible by 4 but not century years unless divisible by 400. • Don’t try to directly translate English
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 6

W10-Control1 - Flow of Control 1 10/10/05 1 Relational...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online