I am trying to write a part of my code. I am using NestWhileList. However, I couldn't find out the right syntax for testing. It should compare previous result and current result and continue if it is True.

Second Question
(This question is not absolutely related to first question.)
In addition, if I can't do that, i will try to create a list without testing. If I create list, how can I compare successive two component of list in a functional way?

I assume you just want to compare current and previous values for the purposes of the stopping condition. Then using NestWhileList with the additional argument as in the comment by ssch is the obvious way to go. This is just another option:

For the stopping criterion, there is one alternative that I've found to be a little faster by trial and error. Instead of NestWhileList, you can use FixedPointList with a custom setting for the option SameTest. The difference is that you then also have to specify a maximum number of iteration steps after which you'd like to terminate unconditionally. This helps prevent runaway loops. And given your specific example with random numbers, that may be a real concern.

The argument 100 limits the calculation to that many trials. The SameTest -> (#2 <= #1 &) is the crucial part, implementing the stopping criterion, where #1 stands for the current argument and #2 for the previous argument. Unlike NestWhileList, these are provided automatically. The function SameTest can be anything you want, Mathematica doesn't care if it actually implements any real "sameness" of successive arguments. That's why it can be used here.

I just remembered another reason why I try to use FixedPoint and FixedPointList when possible: it's in the list of functions that can be compiled.

Finally, another point that may not be what you want: If you need the two arguments inside the function that's being iterated, then you can always do that by making the iterated function into a list that returns its own argument and the computed new value as a tuple. Another approach would be to use FoldList, but that's useful mainly if you don't need to implement a specific stopping criterion.

Mathematica is a registered trademark of Wolfram Research, Inc. While the mark is used herein with the limited permission of Wolfram Research, Stack Exchange and this site disclaim all affiliation therewith.