1 / 8

Conditional Statements

This document provides an overview of conditional statements and logical operators in programming. It covers relational operators, their comparison results, and how they are used in array handling. The section explains how to apply comparisons between arrays and evaluates conditions using logical operators. Concepts such as array addressing, logical evaluations, and practical examples are included. This resource is invaluable for anyone looking to strengthen their understanding of conditional logic in coding.

monifa
Télécharger la présentation

Conditional Statements

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Conditional Statements ผศ.ดร.อนันต์ ผลเพิ่ม Anan Phonphoem http://www.cpe.ku.ac.th/~anan anan@cpe.ku.ac.th

  2. Overview • Relational operators • Logical operators • Condition Statements

  3. Relational Operators

  4. Relational Operators • The comparison result is either • “0” if false • “1” if true • Normally is “Array comparison” • Can be used for “Array addressing”

  5. Array comparison >>c = (a == b) c = 0 0 1 0 >>a = [1 2 3 4]; >>b = [-1 4 3 0]; >>c = (a < b) >>c = (a ~= b) c = 1 1 0 1 c = 0 1 0 0 >>c = (a = b) >>c = (a >= b) c = 1 0 1 1 ??? c = (a = b) | Error: The expression …

  6. Array addressing >>a = [1 2 3 4]; >>b = [-1 4 3 0]; >>c = a(a < b) >>c = b(a == b) c = 3 c = 2 >>c = a(a ~= b) >>c = b(a >= b) c = -1 3 0 c = 1 2 4

  7. More on comparison >> 3 < 5 ans = 1 >>a = [0:4] a = 0 1 2 3 4 >>x =(sqrt(a)>=1) x = 0 1 1 1 1 >>y = a(x) y = 1 2 3 4 >> a = (12 < 7) a = 0

  8. Logical Operators

More Related