~ubuntu-branches/ubuntu/precise/kde-l10n-ptbr/precise-proposed

« back to all changes in this revision

Viewing changes to docs/kdeedu/kturtle/programming-reference.docbook

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2010-11-04 13:16:43 UTC
  • mfrom: (1.9.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20101104131643-dgorc8orjt6y6erj
Tags: 4:4.5.3-0ubuntu1
New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
305
305
<title
306
306
>Operadores booleanos (verdadeiro/falso)</title>
307
307
<para
308
 
>Enquanto os <link linkend="mathematical-operators"
309
 
>operadores matemáticos</link
310
 
> são usados principalmente para os <link linkend="number"
311
 
>números</link
312
 
>, os operadores booleanos são para os <link linkend="boolean-value"
313
 
>valores booleanos</link
 
308
>Where <link linkend="mathematical-operators"
 
309
>mathematical operators</link
 
310
> are mainly for <link linkend="number"
 
311
>numbers</link
 
312
>, boolean operators are for <link linkend="boolean-value"
 
313
>boolean values</link
314
314
> (<userinput
315
 
>verdadeiro</userinput
316
 
> e <userinput
317
 
>falso</userinput
318
 
>). Existem apenas três operadores booleanos, o <userinput
319
 
>e</userinput
 
315
>true</userinput
 
316
> and <userinput
 
317
>false</userinput
 
318
>). There are only three boolean operators, namely: <userinput
 
319
>and</userinput
320
320
>, <userinput
321
 
>ou</userinput
322
 
> e <userinput
323
 
>nao</userinput
324
 
>. O seguinte exemplo de &turtlescript; mostra como usá-los: <screen>
325
 
$e_1_1 = verdadeiro e verdadeiro    # -> verdadeiro
326
 
$e_1_0 = verdadeiro e falso   # -> falso
327
 
$e_0_1 = falso e verdadeiro   # -> falso
328
 
$e_0_0 = falso e falso  # -> falso
329
 
 
330
 
$ou_1_1 = verdadeiro ou verdadeiro    # -> verdadeiro
331
 
$ou_1_0 = verdadeiro ou falso   # -> verdadeiro
332
 
$ou_0_1 = falso ou verdadeiro   # -> verdadeiro
333
 
$ou_0_0 = falso ou falso  # -> falso
334
 
 
335
 
$not_1 = nao verdadeiro   # -> falso
336
 
$not_0 = nao falso  # -> verdadeiro
 
321
>or</userinput
 
322
>, and <userinput
 
323
>not</userinput
 
324
>. The following piece of &turtlescript; shows how to use them: <screen>
 
325
$and_1_1 = true and true    # -> true
 
326
$and_1_0 = true and false   # -> false
 
327
$and_0_1 = false and true   # -> false
 
328
$and_0_0 = false and false  # -> false
 
329
 
 
330
$or_1_1 = true or true    # -> true
 
331
$or_1_0 = true or false   # -> true
 
332
$or_0_1 = false or true   # -> true
 
333
$or_0_0 = false or false  # -> false
 
334
 
 
335
$not_1 = not true   # -> false
 
336
$not_0 = not false  # -> true
337
337
</screen
338
 
> Se usar o <link linkend="the-inspector"
 
338
> Using the <link linkend="the-inspector"
339
339
>inspector</link
340
 
>, poderá ver os valores; contudo, fornecemos estes resultados como pequenos comentários no fim das linhas. O <userinput
341
 
>e</userinput
342
 
> é avaliado como <userinput
343
 
>verdadeiro</userinput
344
 
> apenas se ambos os lados forem <userinput
345
 
>verdadeiro</userinput
346
 
>. O <userinput
347
 
>ou</userinput
348
 
> é avaliado como <userinput
349
 
>verdadeiro</userinput
350
 
> se qualquer um dos lados for <userinput
351
 
>verdadeiro</userinput
352
 
>. Finalmente, o <userinput
353
 
>nao</userinput
354
 
> transforma um <userinput
355
 
>verdadeiro</userinput
356
 
> num <userinput
357
 
>falso</userinput
358
 
> e um <userinput
359
 
>falso</userinput
360
 
> num <userinput
361
 
>verdadeiro</userinput
 
340
> you can see the values, yet we also supply these results as little comments at the end of the lines. <userinput
 
341
>and</userinput
 
342
> evaluates <userinput
 
343
>true</userinput
 
344
> only if both sides are <userinput
 
345
>true</userinput
 
346
>. <userinput
 
347
>or</userinput
 
348
> evaluates <userinput
 
349
>true</userinput
 
350
> if either side of <userinput
 
351
>true</userinput
 
352
>. And <userinput
 
353
>not</userinput
 
354
> turns a <userinput
 
355
>true</userinput
 
356
> into <userinput
 
357
>false</userinput
 
358
> and a <userinput
 
359
>false</userinput
 
360
> into <userinput
 
361
>true</userinput
362
362
>.</para>
363
363
<para
364
364
>Os operadores booleanos são <glossterm
385
385
>. Isto significa que todos os três têm de ser avaliados como "verdadeiro" para imprimir o "olá".</para>
386
386
 
387
387
<para
388
 
>Um exemplo com o <userinput
389
 
>ou</userinput
 
388
>An example with <userinput
 
389
>or</userinput
390
390
>: <screen>
391
391
$n = 1
392
 
se ($n &lt; 10) ou ($n == 2) {
393
 
  imprimir "olá"
 
392
if ($n &lt; 10) or ($n == 2) {
 
393
  print "hello"
394
394
}
395
395
</screen
396
 
> Neste trecho de &turtlescript;, o lado esquerdo do <userinput
397
 
>ou</userinput
398
 
> é avaliado como 'verdadeiro', enquanto o direito é avaliado como 'falso'. Uma vez que um dos dois lados do operador <userinput
399
 
>ou</userinput
400
 
> é 'verdadeiro', o operador <userinput
401
 
>ou</userinput
402
 
> é avaliado como 'verdadeiro'. Isto significa que o 'olá' é impresso.</para>
 
396
> In this piece of &turtlescript; the left side of the <userinput
 
397
>or</userinput
 
398
> is evaluating to 'true', the right side to 'false'. Since of the two side of the <userinput
 
399
>or</userinput
 
400
> operator is 'true', the <userinput
 
401
>or</userinput
 
402
> operator evaluates 'true'. That means "hello" gets printed.</para>
403
403
 
404
404
<para
405
405
>Finalmente, um exemplo com o <userinput
443
443
>variáveis</link
444
444
> (que contenham números) poderão ser comparados entre si, com os operadores de comparação.</para>
445
445
<para
446
 
>Aqui estão todos os possíveis operadores de comparação: <table
 
446
>Here are all possible comparing operators: <table
447
447
> <title
448
 
>Tipos de perguntas</title
 
448
>Types of questions</title
449
449
> <tgroup cols="3"
450
450
> <tbody
451
451
> <row
452
452
> <entry
453
453
><userinput
454
 
>$A == $B</userinput
455
 
></entry
456
 
> <entry
457
 
>é igual</entry
458
 
> <entry
459
 
>a resposta é <quote
460
 
>verdadeira</quote
461
 
> se o <userinput
462
 
>$A</userinput
463
 
> for igual a <userinput
464
 
>$B</userinput
465
 
></entry
466
 
> </row
467
 
> <row
468
 
> <entry
469
 
><userinput
470
 
>$A != $B</userinput
471
 
></entry
472
 
> <entry
473
 
>é diferente</entry
474
 
> <entry
475
 
>a resposta é <quote
476
 
>verdadeira</quote
477
 
> se o <userinput
478
 
>$A</userinput
479
 
> não for igual ao <userinput
480
 
>$B</userinput
481
 
></entry
482
 
> </row
483
 
> <row
484
 
> <entry
485
 
><userinput
486
 
>$A &gt; $B</userinput
487
 
></entry
488
 
> <entry
489
 
>maior que</entry
490
 
> <entry
491
 
>a resposta é <quote
492
 
>verdadeira</quote
493
 
> se o <userinput
494
 
>$A</userinput
495
 
> for maior que o <userinput
496
 
>$B</userinput
497
 
></entry
498
 
> </row
499
 
> <row
500
 
> <entry
501
 
><userinput
502
 
>$A &lt; $B</userinput
503
 
></entry
504
 
> <entry
505
 
>menor que</entry
506
 
> <entry
507
 
>a resposta é <quote
508
 
>verdadeira</quote
509
 
> se <userinput
510
 
>$A</userinput
511
 
> for menor que <userinput
512
 
>$B</userinput
513
 
></entry
514
 
> </row
515
 
> <row
516
 
> <entry
517
 
><userinput
518
 
>$A &gt;= $B</userinput
519
 
></entry
520
 
> <entry
521
 
>maior ou igual a</entry
522
 
> <entry
523
 
>a resposta é <quote
524
 
>verdadeira</quote
525
 
> se <userinput
526
 
>$A</userinput
527
 
> for maior ou igual ao <userinput
528
 
>$B</userinput
529
 
></entry
530
 
> </row
531
 
> <row
532
 
> <entry
533
 
><userinput
534
 
>$A &lt;= $B</userinput
535
 
></entry
536
 
> <entry
537
 
>menor ou igual a</entry
538
 
> <entry
539
 
>a resposta é <quote
540
 
>verdadeira</quote
541
 
> se <userinput
542
 
>$A</userinput
543
 
> for menor ou igual a <userinput
544
 
>$B</userinput
 
454
>A == B</userinput
 
455
></entry
 
456
> <entry
 
457
>equals</entry
 
458
> <entry
 
459
>answer is <quote
 
460
>true</quote
 
461
> if <userinput
 
462
>A</userinput
 
463
> equals <userinput
 
464
>B</userinput
 
465
></entry
 
466
> </row
 
467
> <row
 
468
> <entry
 
469
><userinput
 
470
>A != B</userinput
 
471
></entry
 
472
> <entry
 
473
>not-equals</entry
 
474
> <entry
 
475
>answer is <quote
 
476
>true</quote
 
477
> if <userinput
 
478
>A</userinput
 
479
> does not equal <userinput
 
480
>B</userinput
 
481
></entry
 
482
> </row
 
483
> <row
 
484
> <entry
 
485
><userinput
 
486
>A &gt; B</userinput
 
487
></entry
 
488
> <entry
 
489
>greater than</entry
 
490
> <entry
 
491
>answer is <quote
 
492
>true</quote
 
493
> if <userinput
 
494
>A</userinput
 
495
> is greater than <userinput
 
496
>B</userinput
 
497
></entry
 
498
> </row
 
499
> <row
 
500
> <entry
 
501
><userinput
 
502
>A &lt; B</userinput
 
503
></entry
 
504
> <entry
 
505
>smaller than</entry
 
506
> <entry
 
507
>answer is <quote
 
508
>true</quote
 
509
> if <userinput
 
510
>A</userinput
 
511
> is smaller than <userinput
 
512
>B</userinput
 
513
></entry
 
514
> </row
 
515
> <row
 
516
> <entry
 
517
><userinput
 
518
>A &gt;= B</userinput
 
519
></entry
 
520
> <entry
 
521
>greater than or equals</entry
 
522
> <entry
 
523
>answer is <quote
 
524
>true</quote
 
525
> if <userinput
 
526
>A</userinput
 
527
> is greater than or equals <userinput
 
528
>B</userinput
 
529
></entry
 
530
> </row
 
531
> <row
 
532
> <entry
 
533
><userinput
 
534
>A &lt;= B</userinput
 
535
></entry
 
536
> <entry
 
537
>smaller than or equals</entry
 
538
> <entry
 
539
>answer is <quote
 
540
>true</quote
 
541
> if <userinput
 
542
>A</userinput
 
543
> is smaller than or equals <userinput
 
544
>B</userinput
545
545
></entry
546
546
> </row
547
547
> </tbody
548
548
> </tgroup
549
549
> </table
550
 
> Lembre-se que o $A e o $B têm de ser <link linkend="number"
551
 
>números</link
552
 
> ou <link linkend="assignment-of-variables"
553
 
>variáveis</link
554
 
> que contenham números.</para>
 
550
> Please note that A and B have to be <link linkend="number"
 
551
>numbers</link
 
552
> and <link linkend="assignment-of-variables"
 
553
>variables</link
 
554
> that contain numbers.</para>
555
555
</sect2>
556
556
 
557
557
 
1537
1537
> Irá resultar numa mensagem de erro.</para>
1538
1538
 
1539
1539
<para
1540
 
>Considere o pequeno trecho de código em &turtlescript;: <screen>
 
1540
>Please consider the following piece of &turtlescript;: <screen>
1541
1541
$a = 2004
1542
1542
$b = 25
1543
1543
 
1544
 
# o próximo comando imprime "2029"
1545
 
imprimir $a + $b
1546
 
recuar 30
1547
 
# o próximo comando imprime "2004 mais 25 é igual a 2029"
1548
 
imprimir $a + " mais " + $b + " é igual a " + ($a + $b)
1549
 
recuar 30
 
1544
# the next command prints "2029"
 
1545
print $a + $b
 
1546
backward 30
 
1547
# the next command prints "2004 plus 25 equals 2029"
 
1548
print $a + " plus " + $b + " equals " + ($a + $b)
1550
1549
</screen
1551
 
> Nas duas primeiras linhas, as variáveis <userinput
1552
 
>$a</userinput
1553
 
> e <userinput
1554
 
>$b</userinput
1555
 
> são configuradas como sendo iguais a 2004 e 25. Depois nos dois comandos <userinput
1556
 
>imprimir</userinput
1557
 
> existe um comando <userinput
1558
 
>recuar 30</userinput
1559
 
> no meio são executados. Os comentários antes dos comando <userinput
1560
 
>imprimir</userinput
1561
 
> explicam o que ele está fazendo. O comando <userinput
1562
 
>recuar 30</userinput
1563
 
> está ai para garantir que cada saída está numa nova linha. Como poderá ver, as variáveis poderão ser usadas como se fossem o valor que contêm, podendo usá-las com qualquer tipo de <link linkend="operators"
1564
 
>operadores</link
1565
 
> ou fornecendo-os como entradas na invocação dos <link linkend="commands"
1566
 
>comandos</link
 
1550
> In the first two lines the variables <userinput
 
1551
>a</userinput
 
1552
> and <userinput
 
1553
>b</userinput
 
1554
> are set to 2004 and 25. Then in two <userinput
 
1555
>print</userinput
 
1556
> commands with a <userinput
 
1557
>backward 30</userinput
 
1558
> in between. The comments before the <userinput
 
1559
>print</userinput
 
1560
> commands explain what they are doing. As you see variables can be used just as if their where what they contain, you can use them with any kind of <link linkend="operators"
 
1561
>operators</link
 
1562
> or give them as input when invoking <link linkend="commands"
 
1563
>commands</link
1567
1564
>.</para>
1568
1565
 
1569
1566
<para
1839
1836
> até <link linkend="number"
1840
1837
>número</link
1841
1838
> { ... }</screen>
1842
 
O ciclo <userinput
1843
 
>para</userinput
1844
 
> é um <quote
1845
 
>ciclo de contagem</quote
1846
 
>, &ie;, faz uma contagem para você. O primeiro membro configura a variável com o valor do primeiro ciclo. Em cada iteração, o número é aumentado até atingir o segundo número. <screen>
1847
 
para $x = 1 ate 10 {
1848
 
  imprimir $x * 7
1849
 
  avancar 15
 
1839
The <userinput
 
1840
>for</userinput
 
1841
> loop is a <quote
 
1842
>counting loop</quote
 
1843
>, &ie; it keeps count for you. The first number sets the variable to the value in the first loop. Every loop the number is increased until the second number is reached. <screen>
 
1844
for $x = 1 to 10 {
 
1845
  print $x * 7
 
1846
  forward 15
1850
1847
}
1851
1848
</screen
1852
 
> Cada vez que o código entre chaves é executado, o <userinput
1853
 
>$x</userinput
1854
 
> é incrementado de uma unidade, até que o valor do <userinput
1855
 
>$x</userinput
1856
 
> chegue a 10. O código entre chaves imprime o valor de <userinput
1857
 
>$x</userinput
1858
 
> multiplicado por 7. Depois deste programa terminar a sua execução, você irá ver a tabuada dos 7 na área de desenho. </para>
 
1849
> Every time the code between the brackets is executed the <userinput
 
1850
>$x</userinput
 
1851
> is increased by 1, until <userinput
 
1852
>x</userinput
 
1853
> reaches the value of 10. The code between the brackets prints the <userinput
 
1854
>$x</userinput
 
1855
> multiplied by 7. After this program finishes its execution you will see the times table of 7 on the canvas. </para>
1859
1856
     <para
1860
1857
>O passo padrão para um ciclo é 1, você pode usar um outro valor com <screen
1861
1858
>para <link linkend="assignment-of-variables"