Mercurial > octave
comparison doc/interpreter/stmt.txi @ 21633:dcf8922b724b
Deprecate printf, puts, and scanf. Make fputs a M-file.
* libinterp/corefcn/file-io.cc: extracted printf, puts, and scanf to M-files.
* scripts/deprecated/printf.m: new function, equivalent to version file-io.cc.
* scripts/deprecated/puts.m: new function, equivalent to version file-io.cc.
* scripts/deprecated/scanf.m: new function, equivalent to version file-io.cc.
* scripts/deprecated/module.mk: added printf, puts, and scanf.
* scripts/io/fputs.m: new function, equivalent to version file-io.cc.
* scripts/io/module.mk: added fputs.
* doc/interpreter/io.txi: adapted documentation to current implementation.
* NEWS: announced changes.
* doc/interpreter/basics.txi: replaced printf by fprintf.
* doc/interpreter/stmt.txi: replaced printf by fprintf.
* doc/interpreter/var.txi: replaced printf by fprintf.
* doc/refcard/refcard.tex: removed printf and scanf.
* examples/code/@FIRfilter/display.m: replaced printf by fprintf.
* examples/code/@polynomial/display.m: replaced printf by fprintf.
* scripts/@ftp/display.m: replaced printf by fprintf.
* scripts/general/inputParser.m: replaced printf by fprintf.
* scripts/general/methods.m: replaced printf by fprintf.
* scripts/general/profexplore.m: replaced printf by fprintf.
* scripts/general/profshow.m: replaced printf by fprintf.
* scripts/help/help.m: replaced puts by fputs and printf by fprintf.
* scripts/help/lookfor.m: replaced puts by fputs and printf by fprintf.
* scripts/help/which.m: replaced printf by fprintf.
* scripts/image/imformats.m: replaced printf by fprintf.
* scripts/io/beep.m: replaced puts by fputs.
* scripts/io/textread.m: replaced printf by fprintf.
* scripts/java/javaclasspath.m: replaced printf by fprintf.
* scripts/java/javamem.m: replaced printf by fprintf.
* scripts/miscellaneous/dir.m: replaced printf by fprintf.
* scripts/miscellaneous/dos.m: replaced printf by fprintf.
* scripts/miscellaneous/fact.m: replaced printf by fprintf.
* scripts/miscellaneous/info.m: replaced printf by fprintf.
* scripts/miscellaneous/license.m: replaced printf by fprintf.
* scripts/miscellaneous/ls.m: replaced puts by fputs.
* scripts/miscellaneous/menu.m: replaced printf by fprintf.
* scripts/miscellaneous/mkoctfile.m: replaced printf by fprintf.
* scripts/miscellaneous/private/display_info_file.m:
* scripts/miscellaneous/unix.m: replaced printf by fprintf.
* scripts/miscellaneous/ver.m: replaced printf by fprintf.
* scripts/miscellaneous/what.m: replaced printf by fprintf.
* scripts/ode/ode23.m: replaced printf by fprintf.
* scripts/ode/ode45.m: replaced printf by fprintf.
* scripts/optimization/fminbnd.m: replaced printf by fprintf.
* scripts/optimization/optimset.m: replaced puts by fputs and printf by fprintf.
* scripts/optimization/sqp.m: replaced printf by fprintf.
* scripts/pkg/pkg.m: replaced printf by fprintf.
* scripts/pkg/private/describe.m: replaced printf by fprintf.
* scripts/pkg/private/install.m: replaced printf by fprintf.
* scripts/pkg/private/installed_packages.m: replaced printf by fprintf.
* scripts/pkg/private/list_forge_packages.m: replaced puts by fputs and printf by fprintf.
* scripts/pkg/private/rebuild.m: replaced printf by fprintf.
* scripts/plot/util/__gnuplot_drawnow__.m: replaced puts by fputs and printf by fprintf.
* scripts/signal/stft.m: replaced printf by fprintf.
* scripts/sparse/bicg.m: replaced printf by fprintf.
* scripts/sparse/bicgstab.m: replaced printf by fprintf.
* scripts/sparse/cgs.m: replaced printf by fprintf.
* scripts/sparse/pcg.m: replaced printf by fprintf.
* scripts/sparse/pcr.m: replaced printf by fprintf.
* scripts/sparse/qmr.m: replaced printf by fprintf.
* scripts/statistics/models/logistic_regression.m: replaced printf by fprintf.
* scripts/statistics/tests/anova.m: replaced printf by fprintf.
* scripts/statistics/tests/bartlett_test.m: replaced printf by fprintf.
* scripts/statistics/tests/chisquare_test_homogeneity.m: replaced printf by fprintf.
* scripts/statistics/tests/chisquare_test_independence.m: replaced printf by fprintf.
* scripts/statistics/tests/cor_test.m: replaced printf by fprintf.
* scripts/statistics/tests/f_test_regression.m: replaced printf by fprintf.
* scripts/statistics/tests/hotelling_test.m: replaced printf by fprintf.
* scripts/statistics/tests/hotelling_test_2.m: replaced printf by fprintf.
* scripts/statistics/tests/kolmogorov_smirnov_test.m: replaced printf by fprintf.
* scripts/statistics/tests/kolmogorov_smirnov_test_2.m: replaced printf by fprintf.
* scripts/statistics/tests/kruskal_wallis_test.m: replaced printf by fprintf.
* scripts/statistics/tests/manova.m: replaced printf by fprintf.
* scripts/statistics/tests/mcnemar_test.m: replaced printf by fprintf.
* scripts/statistics/tests/prop_test_2.m: replaced printf by fprintf.
* scripts/statistics/tests/run_test.m: replaced printf by fprintf.
* scripts/statistics/tests/sign_test.m: replaced printf by fprintf.
* scripts/statistics/tests/t_test.m: replaced printf by fprintf.
* scripts/statistics/tests/t_test_2.m: replaced printf by fprintf.
* scripts/statistics/tests/t_test_regression.m: replaced printf by fprintf.
* scripts/statistics/tests/u_test.m: replaced printf by fprintf.
* scripts/statistics/tests/var_test.m: replaced printf by fprintf.
* scripts/statistics/tests/welch_test.m: replaced printf by fprintf.
* scripts/statistics/tests/wilcoxon_test.m: replaced printf by fprintf.
* scripts/statistics/tests/z_test.m: replaced printf by fprintf.
* scripts/statistics/tests/z_test_2.m: replaced printf by fprintf.
* scripts/strings/strtok.m: replaced printf by fprintf.
* scripts/testfun/__run_test_suite__.m: replaced puts by fputs and printf by fprintf.
* scripts/testfun/demo.m: replaced printf by fprintf.
* scripts/testfun/example.m: replaced printf by fprintf.
* scripts/testfun/private/compare_plot_demos.m: replaced printf by fprintf.
* scripts/testfun/rundemos.m: replaced printf by fprintf.
* scripts/testfun/runtests.m: replaced puts by fputs and printf by fprintf.
* scripts/testfun/speed.m: replaced printf by fprintf.
* scripts/testfun/test.m: replaced printf by fprintf.
* scripts/time/calendar.m: replaced puts by fputs and printf by fprintf.
* test/io.tst: replaced printf by fprintf.
author | Kai T. Ohlhus <k.ohlhus@gmail.com> |
---|---|
date | Wed, 20 Apr 2016 17:53:10 +0200 |
parents | dba88797f69f |
children | 96518f623c91 |
comparison
equal
deleted
inserted
replaced
21632:e3c44a120a8c | 21633:dcf8922b724b |
---|---|
113 Here is an example: | 113 Here is an example: |
114 | 114 |
115 @example | 115 @example |
116 @group | 116 @group |
117 if (rem (x, 2) == 0) | 117 if (rem (x, 2) == 0) |
118 printf ("x is even\n"); | 118 fprintf ("x is even\n"); |
119 else | 119 else |
120 printf ("x is odd\n"); | 120 fprintf ("x is odd\n"); |
121 endif | 121 endif |
122 @end group | 122 @end group |
123 @end example | 123 @end example |
124 | 124 |
125 In this example, if the expression @code{rem (x, 2) == 0} is true (that | 125 In this example, if the expression @code{rem (x, 2) == 0} is true (that |
126 is, the value of @code{x} is divisible by 2), then the first | 126 is, the value of @code{x} is divisible by 2), then the first |
127 @code{printf} statement is evaluated, otherwise the second @code{printf} | 127 @code{fprintf} statement is evaluated, otherwise the second @code{fprintf} |
128 statement is evaluated. | 128 statement is evaluated. |
129 | 129 |
130 The third and most general form of the @code{if} statement allows | 130 The third and most general form of the @code{if} statement allows |
131 multiple decisions to be combined in a single statement. It looks like | 131 multiple decisions to be combined in a single statement. It looks like |
132 this: | 132 this: |
150 @code{else} clause is present, its body is executed. Only one | 150 @code{else} clause is present, its body is executed. Only one |
151 @code{else} clause may appear, and it must be the last part of the | 151 @code{else} clause may appear, and it must be the last part of the |
152 statement. | 152 statement. |
153 | 153 |
154 In the following example, if the first condition is true (that is, the | 154 In the following example, if the first condition is true (that is, the |
155 value of @code{x} is divisible by 2), then the first @code{printf} | 155 value of @code{x} is divisible by 2), then the first @code{fprintf} |
156 statement is executed. If it is false, then the second condition is | 156 statement is executed. If it is false, then the second condition is |
157 tested, and if it is true (that is, the value of @code{x} is divisible | 157 tested, and if it is true (that is, the value of @code{x} is divisible |
158 by 3), then the second @code{printf} statement is executed. Otherwise, | 158 by 3), then the second @code{fprintf} statement is executed. Otherwise, |
159 the third @code{printf} statement is performed. | 159 the third @code{fprintf} statement is performed. |
160 | 160 |
161 @example | 161 @example |
162 @group | 162 @group |
163 if (rem (x, 2) == 0) | 163 if (rem (x, 2) == 0) |
164 printf ("x is even\n"); | 164 fprintf ("x is even\n"); |
165 elseif (rem (x, 3) == 0) | 165 elseif (rem (x, 3) == 0) |
166 printf ("x is odd and divisible by 3\n"); | 166 fprintf ("x is odd and divisible by 3\n"); |
167 else | 167 else |
168 printf ("x is odd\n"); | 168 fprintf ("x is odd\n"); |
169 endif | 169 endif |
170 @end group | 170 @end group |
171 @end example | 171 @end example |
172 | 172 |
173 Note that the @code{elseif} keyword must not be spelled @code{else if}, | 173 Note that the @code{elseif} keyword must not be spelled @code{else if}, |
294 @example | 294 @example |
295 @group | 295 @group |
296 A = 7; | 296 A = 7; |
297 switch (A) | 297 switch (A) |
298 case @{ 6, 7 @} | 298 case @{ 6, 7 @} |
299 printf ("variable is either 6 or 7\n"); | 299 fprintf ("variable is either 6 or 7\n"); |
300 otherwise | 300 otherwise |
301 printf ("variable is neither 6 nor 7\n"); | 301 fprintf ("variable is neither 6 nor 7\n"); |
302 endswitch | 302 endswitch |
303 @end group | 303 @end group |
304 @end example | 304 @end example |
305 | 305 |
306 As with all other specific @code{end} keywords, @code{endswitch} may be | 306 As with all other specific @code{end} keywords, @code{endswitch} may be |
682 break; | 682 break; |
683 endif | 683 endif |
684 div++; | 684 div++; |
685 endwhile | 685 endwhile |
686 if (rem (num, div) == 0) | 686 if (rem (num, div) == 0) |
687 printf ("Smallest divisor of %d is %d\n", num, div) | 687 fprintf ("Smallest divisor of %d is %d\n", num, div) |
688 else | 688 else |
689 printf ("%d is prime\n", num); | 689 fprintf ("%d is prime\n", num); |
690 endif | 690 endif |
691 @end group | 691 @end group |
692 @end example | 692 @end example |
693 | 693 |
694 When the remainder is zero in the first @code{while} statement, Octave | 694 When the remainder is zero in the first @code{while} statement, Octave |
705 @group | 705 @group |
706 num = 103; | 706 num = 103; |
707 div = 2; | 707 div = 2; |
708 while (1) | 708 while (1) |
709 if (rem (num, div) == 0) | 709 if (rem (num, div) == 0) |
710 printf ("Smallest divisor of %d is %d\n", num, div); | 710 fprintf ("Smallest divisor of %d is %d\n", num, div); |
711 break; | 711 break; |
712 endif | 712 endif |
713 div++; | 713 div++; |
714 if (div*div > num) | 714 if (div*div > num) |
715 printf ("%d is prime\n", num); | 715 fprintf ("%d is prime\n", num); |
716 break; | 716 break; |
717 endif | 717 endif |
718 endwhile | 718 endwhile |
719 @end group | 719 @end group |
720 @end example | 720 @end example |
744 | 744 |
745 for x = vec | 745 for x = vec |
746 if (rem (x, 2) != 0) | 746 if (rem (x, 2) != 0) |
747 continue; | 747 continue; |
748 endif | 748 endif |
749 printf ("%d\n", x); | 749 fprintf ("%d\n", x); |
750 endfor | 750 endfor |
751 @end group | 751 @end group |
752 @end example | 752 @end example |
753 | 753 |
754 If one of the elements of @var{vec} is an odd number, this example skips | 754 If one of the elements of @var{vec} is an odd number, this example skips |
761 | 761 |
762 @example | 762 @example |
763 @group | 763 @group |
764 for x = vec | 764 for x = vec |
765 if (rem (x, 2) == 0) | 765 if (rem (x, 2) == 0) |
766 printf ("%d\n", x); | 766 fprintf ("%d\n", x); |
767 endif | 767 endif |
768 endfor | 768 endfor |
769 @end group | 769 @end group |
770 @end example | 770 @end example |
771 | 771 |