delivered the opinion of the Court.
In a petition for habeas corpus filed in the District Court of San Juan, Juan Ramón González alleges in brief that sometime in August 1919 he was accused and convicted of rape by the District Court of Aguadilla, and sentenced to 15 years’ imprisonment in the penitentiary; that he was not represented by counsel either at the arraignment, when he was actually sentenced, nor at any other stage of the proceeding; that in 1937 he was accused in the District Court of San Juan of a subsequent offense of murder in the first degree, on the ground of his previous conviction of rape; that the case was heard by the jury which rendered a verdict of murder in the second degree as a subsequent offense, the court thereupon sentencing him to 30 years’ imprisonment in the penitentiary; that he could not be sentenced for a subsequent crime of murder in the second degree inasmuch as the judgment originally entered in 1919 for the crime of rape was void since he was not represented by counsel at the times he has indicated; and that since the judgment rendered in the case of rape was invalid, he was deprived of the due process of law when he was sentenced for a subsequent offense of murder in the second degree.
The writ was issued, the Warden of the Insular Penitentiary filed the return and the case was heard by the lower court which discharged the writ. Petitioner appealed. He contends that the lower court erred in holding that the judgment entered by the District Court of Aguadilla was valid and could serve as a basis to accuse him of a subsequent offense of murder in the second degree, and in deciding that the judgment entered against him for a subsequent offense of murder in the second degree was valid.
Section- 56 of the Penal Code provides that “Every person who, having been convicted of any offense punishable by imprisonment in the penitentiary commits any crime after such conviction, is punishable therefor as follows: (1) If the offense of which such person is subsequently convicted is such *737that, upon a first conviction, an offender would be punishable by imprisonment in the penitentiary, for any term exceeding five years, such person is punishable by imprisonment in the penitentiary not less than ten years. . .
The allegation-of a previous conviction of another offense does not charge a crime by itself. Its only purpose is to bring the case within the statute and to impose on the-accused the heavier penalty fixed thereby. Moore v. Missouri, 159 U. S. 673, 677; McDonald v. Massachusetts, 180 U. S. 311, 313; Graham v. West Virginia, 224 U. S. 616, 623; Carlesi v. New York, 233 U. S. 51, 58.
Assuming that the judgment in the case of rape is void on any of the grounds alleged now by the petitioner, is habeas corpus the proper proceeding to raise such invalidity when same was not raised within the prosecution for murder? We do not think so. When the petitioner was accused of ■ murder he was clearly informed that he was being prosecuted for a subsequent offense. It was then that he should have raised the question of the invalidity of the previous conviction of rape. In default thereof, the question was waived and he is now precluded from raising it in the habeas corpus proceeding.
As decided by the Supreme Court of Minnesota in Willoughby v. Utecht, (1947) 27 N. W. 2d 779, 171 A.L.R. 535, 540 “Where a judgment is based on an invalid judgment, the remedy is by a direct proceeding in the action in which the judgment was rendered showing that there is no basis for it because of the invalidity of the judgment on which it was based, and not by an attack on the judgment in a separate, independent proceeding, as here. So long as the judgment based on a prior judgment stands, it is immune from attack upon the ground that the prior judgment is invalid.” In the cited volume of American Law Reports it is further stated, on p. 542, that “According to most of the cases dealing with this specific question the rule is that a prisoner convicted and sentenced as a second offender cannot base his *738right to relief from punishment therefor by a writ of habeas corpus on the ground that one or several of his prior convictions were improper or invalid,” citing, among others, the case of Ex parte Basuino (1943) 22 Cal. 2d 247, 138 P. 2d 297.
In Gayes v. New York, 332 U. S. 145, the accused, a minor 16 years old, was prosecuted in 1938 for burglary in the third degree and petty larceny. He was asked whether he desired the aid of counsel and he answered in the negative. After trial, the court sentenced him and ordered his commitment to a vocational school. On October 14, 1941 Gayes pleaded guilty to a new charge of burglary in the third degree. In a separate proceeding to vacate the judgment rendered against him, his contention was that said judgment was improperly rendered by the inclusion of the previous judgment ordering his commitment to the vocational school. The question was adversely decided by the courts of the State of New York and the case was heard in the National Supreme Court, whereupon the latter decided that when the case was called for the subsequent offense in 1941 Gayes had full opportunity to contest the validity of the earlier sentence, especially when said sentence was included in the proceeding within which the sentence which he is now serving was entered, and that since the previous judgment rendered against him was not challenged within the process leading up to the second sentence, the petitioner could not, in the proceeding before the lower court, challenge by a flank attack the sentence of 1938.
Since petitioner failed to challenge the previous conviction of rape within the very case against him for the subsequent offense of murder, he is not entitled now to the relief requested.
The order appealed from will be affirmed.