The problem of For+RegionPlot

I type the following code in Mathematica 11:

For[n = 1, n <= 3, n++,
RegionPlot[x^2 + y^3 < n, {x, -2, 2}, {y, -2, 2}]
]

Then I press Shift+Enter, but Mathematica does not output any figures. Where is the problem? Thanks in advance.

• This is a common mistake for users new to Mathematica, or coming from earlier versions. Plots return Graphics expressions rather than displaying them as side-effects. See (47123). You could add Print but generally a better method is to replace For with Table: Table[RegionPlot[x^2 + y^3 < n, {x, -2, 2}, {y, -2, 2}], {n, 1, 3}]. You can further format that output with Column or GraphicsColumn as desired, or animate it with ListAnimate. – Mr.Wizard Aug 16 '16 at 8:24
• Note: does there exist a canonical Q&A on this issue? If not I think a post should be made in (18393) regarding this, as it has come up quite often. – Mr.Wizard Aug 16 '16 at 8:28
• Mr.Wizard: Thank you for your comment. – Wei-Cheng Liu Aug 16 '16 at 8:31

It depends on what your aim. If it is just to 'print' 3 graphics:

For[n = 1, n <= 3, n++,
Print@RegionPlot[x^2 + y^3 < n, {x, -2, 2}, {y, -2, 2}]]

If you want an object you can use and refer to:

f[x_, y_] := x^2 + y^3
rps=RegionPlot[f[x, y] < #, {x, -2, 2}, {y, -2, 2}] & /@ Range

This is also a useful link with respect to loops in Mathematica.

• ubpdqn: Thank you for your answer. – Wei-Cheng Liu Aug 16 '16 at 8:32
• @Wei-ChengLiu you're welcome. I had exactly the same question when I first started using Mma. Have fun:) – ubpdqn Aug 16 '16 at 8:34
• Surely in this case Table[]>For[] – Feyre Aug 16 '16 at 9:53
• @Feyre as you and Mr.Wizard have suggested Table may be natural alternative. I provided link to motivate looking at alternatives. – ubpdqn Aug 16 '16 at 9:57
• @Feyre & ubpdqn Thank you for your comments. – Wei-Cheng Liu Aug 16 '16 at 11:53

For fun

Example

Manipulate[
RegionPlot[x^2 + y^3 < n, {x, -2, 2}, {y, -2, 2}],
{n, 1, 3, 1}
]
• e.doroskevic: Thank you for your answer. – Wei-Cheng Liu Aug 16 '16 at 8:32
• @Wei-ChengLiu you are most welcome – e.doroskevic Aug 16 '16 at 8:34