if
Help Contents
First Steps In Logo
Built-in instructions
Controlling program flow
if
if
One of them, if, is used to tell Logo to execute a list of instructions only if a given condition is fulfilled.
if :a>0 [print "positive]
Here you say Logo to print the word positive only if the value of a is greater than zero.
Apparently if enables you to define not only what to do when something is true, but also what to do otherwise:
if :a>0
[print "positive]
[print "negative "or "zero]
To make shorter line Logo agrees to look for lists of instructions not only in the line where if is used, but also on the next line too.
Anyway, the condition must always be on the same line - right after if.
Speaking of conditions, Logo decides whether one is fulfilled only by its value.
It its value is the word true, then the condition is fulfilled. Otherwise it is not.
Examples:
References:
SketchPad (advanched)(10), Bojo-Triangle (advanced)(9), Bojo-triangle-inscribed (advanced)(9), fly(9), Defining actions(8), Point-vector arithmetic operators(8), ZoomRotate(8), pointonP(8), isec_circlecircle(7), pointon(7), Cubic (3d fractal)(6), Logical operators ( and, or, not )(6), Turn left, turn right (lt, rt )(6), triFrac (3d)(6), Hanoi (3d Towers of Hanoi solver)(5), How to say actions(5), Recognizing Words(5), Sign functions ( abs, neg, sign )(5), bl(5), def_position(5), isec_linecircle(5), How to say variables(4), Reflection(4), bf(4), type(4), I don't want it all. I need just a bit of it. ( first, last, bf, bl, item )(3), always_rotate(3), first(3), fput(3), get_initial(3), label_position(3), last(3), lput(3), turtle(3), CatDog (simple)(2), Honey (3d)(2), How to say words and lists(2), Logo and Languages(2), More things to do(2), Other functions(2), The Logo Turtle(2), Walker (advanced 3d)(2), fact (Factorial Operator, simple recursion)(2), forward(2), image(2), isec_lineline(2), item(2), local(2), member(2), memberP(2), pow(2), print(2), readkey(2), readword(2), rgb_(2), segment(2), Citadel Problem, Controlling program flow, DNA (3d), Dancing turtle ( fd, bk ), Decoration (fractal), Fern (3d), House (3d), Integral (simple 3d), Lines (simple), Mathematical functions (guide), Mouse (simple), Mousedraw (simple), Operators for comparing, Polyhedra-fractals (3d fractal), Pythagoras (advanced), PythagorasTree (fractal), Rose (3d), Star (fractal), Types of things, Under cover, What is this, angle, angleP, circle, circleP, ellipse, ellipseP, fog, get_focus, get_radius, graphix, graphix.circle, graphix.ellipse, graphix.hyperbola, graphix.parabola, graphix.subellipse, hyperbola, hyperbolaP, isec, isec_pointcircle, isec_pointline, isec_pointpoint, line, lineP, normalize, parabolaP, pointP, rainbow, ray, rayP, repeat, run, segmentP, setP, setxy, sminus, ssection, sunion, suptype, vector, vectorP, wait, while